package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author hp
	 */
	public class Main extends Sprite 
	{
		//var hero:Hero = new Hero(stage);
		var oldX:Number = 20;
		var oldY:Number = 20;
		
		var curX:Number = 0;
		var curY:Number = 0;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			stage.addEventListener(MouseEvent.CLICK, mClck, false, 0, true);
			
			//addChild(hero);
			
			this.graphics.beginFill(0xFF0000, 1);
			this.graphics.drawCircle(oldX, oldY, 3);
			this.graphics.endFill();
			
			this.graphics.lineStyle(3, 0x000000, 1);
			this.graphics.moveTo(40, 10);
			this.graphics.lineTo(600, 10);
			this.graphics.lineTo(600, 400);
			this.graphics.moveTo(560, 400);
			this.graphics.lineTo(0, 400);
			this.graphics.lineTo(0, 10);
			
			this.graphics.moveTo(300, 10);
			this.graphics.lineTo(300, 230);
			this.graphics.lineTo(150, 230);
			this.graphics.lineTo(150, 100);
			
			this.graphics.moveTo(180, 400);
			this.graphics.lineTo(180, 270);
			
			this.graphics.moveTo(0, 300);
			this.graphics.lineTo(100, 300);
			this.graphics.lineTo(100, 100);
			
			this.graphics.moveTo(40, 10);
			this.graphics.lineTo(40, 200);
			
			this.graphics.moveTo(600, 200);
			this.graphics.lineTo(350, 200);
			
			this.graphics.lineTo(350, 300);
			this.graphics.lineTo(250, 300);
		}
		
		private function mClck(e:MouseEvent):void
		{
			this.graphics.beginFill(0x000000, 1);
			curX = e.localX;
			curY = e.localY;
			//this.graphics.lineTo(oldX, oldY);
			
			this.graphics.moveTo(oldX, oldY);
			this.graphics.lineStyle(1, 0x00FF00, 1, false);
			this.graphics.lineTo(curX, curY);
			this.graphics.drawCircle(curX, curY, 5);
			this.graphics.endFill();
			
			oldX = curX;
			oldY = curY;
			
			//hero.move(stage.mouseX, stage.mouseY);
			//addChild(hero);
		}
		
	}
	
}